*---------------------------------------------------------------------------------
*			Waqf As Islamic Wealth Instruments In Poverty Reduction
*---------------------------------------------------------------------------------
*Setting Data 
global data "C:\Users\ASUS\Documents\155. Wakaf and poverty\1. Data"
global hasil "C:\Users\ASUS\Documents\155. Wakaf and poverty\3. Hasil"

*Get Data from world bank
wbopendata, language(en - English) country() topics() indicator(SI.POV.NAPR.ZS - Poverty Rate (in % of population) ; SI.POV.BPL - Number of people live below the poverty line (in number of people); SI.POV.NSEV - Poverty Severity (index); SE.JRSEC.NENR.ZS - Net Enrollment Ratio: Junior Secondary (in %) ; SE.PRM.NENR.ZS - Net Enrollment Ratio: Primary (in %); SE.SRSEC.NENR.ZS - Net Enrollment Ratio: Senior Secondary (in %); IDX.HDI.REV - Human Development Index, revised method; SL.TLF - Number of people in labor force; HOU.ELC.ACSN.ZS - Household Access to Electricity: Total (in % of total household); HOU.XPD.PC.CR - Household per capita expenditure (in IDR)) clear long

drop if regexm(countryname, "Prop.")
tempfile indodapoer
save `indodapoer'

*Input and preproseing database form siwak kemenag
import excel "$data\Data tanah wakaf Kabupaten.xlsx", sheet("Data tanah wakaf Kabupaten") firstrow clear
gen id=lower( KantorKementerianAgama)
replace id=subinstr(id, "kabupaten", "", .)
replace id=subinstr(id, "kab.", "", .)
replace id=subinstr(id, "kab ", "", .)
replace id=subinstr(id, "kota ", "", .)
replace id=subinstr(id, "kota.", "", .)
replace id=subinstr(id, " ", "", .)
replace id=subinstr(id, "-", "", .)
replace id=subinstr(id, "dhamasraya", "dharmasraya", .)
replace id=subinstr(id, "kendari", "kendaricity", .)
replace id=subinstr(id, "kep.seribu", "kepulauanseribu",  .)
replace id=subinstr(id, "mahakamulu", "mahakamhulu", .)
replace id=subinstr(id, "makasar", "makassar", .)
replace id=subinstr(id, "pangkajenedankepulauan", "pangkajenekepulauan", .)
replace id=subinstr(id, "penajampasirutara", "penajampaserutara", .)
replace id=subinstr(id, "penukalababpematangilir", "penukalabablematangilir", .)
replace id=subinstr(id, "sarolangan", "sarolangun", .)
replace id=subinstr(id, "kuantansengingi", "kuantansingingi", .)
replace id="kotabaru" if  id== "baru"
replace id=subinstr(id, "banjarkotabaru", "banjarbaru", .)
replace id=subinstr(id, "bovendigul", "bovendigoel", .)
replace id=subinstr(id, "meranti", "kepulauanmeranti", .)
replace id=subinstr(id, "kep.anambas", "kepulauananambas", .)
replace id=subinstr(id, "kep.mentawai", "kepulauanmentawai", .)
replace id=subinstr(id, "kep.talaud", "kepulauantalaud", .)
replace id=subinstr(id, "selayar", "kepulauanselayar", .)
replace id=subinstr(id, "morotai", "pulaumorotai", .)
replace id=subinstr(id, "biak", "biaknumfor", .)
replace id=subinstr(id, "tanahgrogot", "pasir", .)
replace id=subinstr(id, "tidorekepulauan", "kepulauantidore", .)
replace id=subinstr(id, "yapen", "kepulauanyapen", .)
tempfile data 
save `data'

*id connected between indodapoer and BPS code
import excel "$data\Indodapoer to BPS code.xlsx", sheet("Sheet1") firstrow clear

gen id =lower(provincesname)
replace id=subinstr(id, ", kab.", "", .)
replace id=subinstr(id, ", kab", "", .)
replace id=subinstr(id, ", kota", "", .)
replace id=subinstr(id, "adm. ", "", .)
replace id=subinstr(id, " ", "", .)
replace id=subinstr(id, "-", "", .)
*replace id=subinstr(id, "kepulauan", "",.)
merge m:m id using `data'
keep if _m==3
drop _m
ren provincescode countrycode
merge 1:m countrycode using `indodapoer'
drop _m
for var Jumlah LuasHa SudahSertifikatjumlah SudahSertifikatluas BelumSertifikatjumlah belumSertifikatluas hou_xpd_pc_cr sl_tlf: gen lX=ln(X)

tostring bpscode, replace
gen prov=substr( bpscode,1,2)
destring prov, replace 
egen idpanel=group(countrycode)
xtset idpanel year  

save "$hasil\Hasil Penelitian Habibi Mareta", replace 
*analitic regresi Ordinary least square 

reg si_pov_napr_zs lJumlah lSudahSertifikatjumlah lBelumSertifikatjumlah se_jrsec_nenr_zs se_prm_nenr_zs se_srsec_nenr_zs hou_elc_acsn_zs i.prov , robust
outreg2 using "$hasil\Hasil Penelitian.xls", replace ctitle(OLS)  dec(3) 
reg si_pov_napr_zs lJumlah   se_jrsec_nenr_zs se_prm_nenr_zs se_srsec_nenr_zs hou_elc_acsn_zs i.prov , robust
outreg2 using "$hasil\Hasil Penelitian.xls", append ctitle(OLS)  dec(3) 
reg si_pov_napr_zs  lSudahSertifikatjumlah  se_jrsec_nenr_zs se_prm_nenr_zs se_srsec_nenr_zs hou_elc_acsn_zs i.prov , robust
outreg2 using "$hasil\Hasil Penelitian.xls", append ctitle(OLS)  dec(3) 
reg si_pov_napr_zs lBelumSertifikatjumlah se_jrsec_nenr_zs se_prm_nenr_zs se_srsec_nenr_zs hou_elc_acsn_zs i.prov , robust
outreg2 using "$hasil\Hasil Penelitian.xls", append ctitle(OLS)  dec(3) 


*analitic regresi fix effect model 
xtreg si_pov_napr_zs lJumlah lSudahSertifikatjumlah lBelumSertifikatjumlah se_jrsec_nenr_zs se_prm_nenr_zs se_srsec_nenr_zs hou_elc_acsn_zs , fe i(prov)
outreg2 using "$hasil\Hasil Penelitian.xls", append ctitle(FE)  dec(3) 
xtreg si_pov_napr_zs lJumlah  se_jrsec_nenr_zs se_prm_nenr_zs se_srsec_nenr_zs hou_elc_acsn_zs , fe i(prov)
outreg2 using "$hasil\Hasil Penelitian.xls", append ctitle(FE)  dec(3) 
xtreg si_pov_napr_zs  lSudahSertifikatjumlah  se_jrsec_nenr_zs se_prm_nenr_zs se_srsec_nenr_zs hou_elc_acsn_zs , fe i(prov)
outreg2 using "$hasil\Hasil Penelitian.xls", append ctitle(FE)  dec(3) 
xtreg si_pov_napr_zs lBelumSertifikatjumlah se_jrsec_nenr_zs se_prm_nenr_zs se_srsec_nenr_zs hou_elc_acsn_zs , fe i(prov)
outreg2 using "$hasil\Hasil Penelitian.xls", append ctitle(FE)  dec(3) 
cd "$hasil"
gen sample=e(sample)
asdoc sum si_pov_napr_zs Jumlah SudahSertifikatjumlah BelumSertifikatjumlah se_jrsec_nenr_zs se_prm_nenr_zs se_srsec_nenr_zs hou_elc_acsn_zs if sample==1, save(summary statistic)

